import {layoutRouter, managerRouter, spManagerRouter} from '../router/index'

export default {
    // 是否存在当前路由
    getRouter(to, authTree) {
        let auths = authTree || window.routeAuth
        return to.meta.auth ? auths[to.meta.auth] : true
    },
    // 得到第一个显示的菜单
    jumpFirstRouter(authTree) {
        let auths = authTree || window.routeAuth,
            first = false, routerList = [], router
        routerList = [...layoutRouter, ...managerRouter, ...spManagerRouter]
        routerList.forEach(menu => {
            if (auths[menu.auth] && !first) {
                menu.children.forEach(list => {
                    if (list.meta.noJump) {
                        list.children.forEach(sub => {
                            if (auths[sub.meta.auth] && !first) {
                                router = sub
                                first = true
                            }
                        })
                    } else {
                        if (auths[list.meta.auth] && !first) {
                            router = list
                            first = true
                        }
                    }
                })
            }
        })
        return router
    }
}
